
import html2Canvas from 'html2canvas'
import JsPDF from 'jspdf'
export default {
  install(Vue, options) {
    Vue.prototype.getPdf = function () {
      var title = this.htmlTitle;
       return html2Canvas(document.querySelector('#pdfDom'), {
        scale:2,
        allowTaint: true
      }).then(function (canvas) {
          let contentWidth = canvas.width
          let contentHeight = canvas.height
          let width = Number(canvas.style.width.toString().substr(0,canvas.style.width.toString().length - 2));
          let height = Number(canvas.style.height.toString().substr(0,canvas.style.height.toString().length - 2));
          let scaleL = width/592.28;
          let nowHeight = height/scaleL;
          let pageHeight = contentWidth / 592.28 * 841.89
          let leftHeight = contentHeight
          let position = 0
          let imgWidth = 592.28
          let imgHeight = 592.28 / contentWidth * contentHeight
          let pageData = canvas.toDataURL('image/jpeg', 1.0)
          let PDF = new JsPDF('p', 'pt', [592.28,nowHeight])
          PDF.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight)
           // PDF.save(title + '.pdf')
            var datauri = PDF.output('dataurlstring');
            return datauri;

        }
      )
    }
  }
}
